package com.fly;

import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;

/**
 * Created by SWan on 2017/6/19.
 */
public class TimerServer {

    public static void main(String[] args) {
        int port = 8080;
        if(args!=null && args.length>0){
            port = Integer.valueOf(args[0]);
        }

        ServerSocket server = null;

        try {
            server = new ServerSocket(port);
            System.out.println("TimeServer is start,port:" + port);
            Socket socket = null;
            while (true){
                socket = server.accept();
                new Thread(new TimerServerHandler(socket)).start();
            }
        } catch (IOException e) {
            e.printStackTrace();
        }finally {
            if(server!=null){
                System.out.println("the TimeServer is close");
                try {
                    server.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
                server = null;
            }
        }
    }
}
